<template>
  <div style="text-align: center">
    <img
      style="width: 80%; text-align: center; margin-top: 60px"
      src="https://msmk2019.oss-cn-shanghai.aliyuncs.com/uploads/image/2019pILfAg7Avr1567732916.png"
      alt=""
    />
    <!-- 发送验证码 -->
    <van-field
      v-model="sms"
      center
      clearable
      label=""
      placeholder="请输入手机号"
      style="margin-top: 32px"
    >
      <template #button>
        <van-button @click="yzma" size="small" type="primary"
          >发送验证码</van-button
        >
      </template>
    </van-field>

    <!-- 验证码输入框 -->
    <van-cell-group>
      <van-field v-model="value" label="" placeholder="请输入短信验证码" />
    </van-cell-group>
    <van-cell-group class="zhuce">
      <p>*没有注册过的会直接注册账号</p>
      <p @click="zhuce">使用密码登陆</p>
    </van-cell-group>
    <div style="margin: 16px">
      <van-button
        round
        block
        type="primary"
        @click="tologin"
        native-type="submit"
      >
        登陆
      </van-button>
    </div>
  </div>
</template>

<script>
import { yzm, login } from "../../../../../request/http";
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      value: "",
      // 手机号框框
      sms: "",
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    
  },
  methods: {
    // 跳转登陆
    zhuce() {
      this.$router.push("/login");
    },
    // 发送验证码
    yzma() {
      yzm({ mobile: this.sms, sms_type: "login" }).then((res) => {
        console.log(res);
        if (res == true) {
          this.$toast.success("验证码发送成功");
        }
      });
    },
    // 验证码登陆
    tologin() {
      const queryInfo = {
        mobile: this.sms,
        type: 2,
        client: 1,
        sms_code: this.value,
      };
      // 登陆data
      login(queryInfo).then((res) => {
        console.log(res);
        if (res) {
          this.$toast.success("登陆成功");
          localStorage.setItem("adminToken", res.remember_token);
          localStorage.setItem("data", JSON.stringify(res));
          if (res.is_new == 1) {
            this.$router.push({
              name: "userpassword",
              params: {
                mobile: this.sms,
                sms_code: this.value,
              },
            });
          }else{
            this.$router.push("/home/person")
          }
        }
      });
    },
  },
};
</script>

<style lang='scss' scoped>
.zhuce {
  box-sizing: border-box;
  padding: 0px 20px;
  font-size: 12px;
  justify-content: space-between;
  display: flex;
  color: #969799;
}
</style>
